<template>
	<view class="page">
		<u-sticky bg-color="#fff">
			<view :style="{ padding: '20rpx'}">
				<u-input v-model="queryForm.title" placeholder="搜索你感兴趣的内容" suffix-icon="search" clearable
					suffix-icon-style="color: #909399" shape="circle" border="none" font-size="13px"
					@clear="clearSearch" @confirm="handleSearch" :custom-style="{
		      background: '#F4F4F4',
		      padding: '6px 12px',
		      boxShadow: '0 0 20rpx rgba(186, 186, 186, 0.1)',
		    }" />
				<view class="chooseCup"
					style="color: #000 !important;margin: 20rpx 0 0 !important;display: flex;justify-content: space-around;">
					<view class="" style="display: flex;align-items: center;">
						<vvSelect :list="typeList" label="name" valueKey="id" placeholder-style="color: #F5F5F5"
							 :placeholder="placeholder1" ref="vvSelect" @change="tabChange">
						</vvSelect>
						<view class="" style="margin-left: 8rpx;">
							<u-icon name="arrow-down" size="16"></u-icon>
						</view>
					</view>
					<view class="" style="display: flex;align-items: center;">
						<vvSelect :list="orderList" label="name" valueKey="id" placeholder-style="color: #F5F5F5"
						 :placeholder="placeholder2" ref="vvSelect" @change="orderChange">
						</vvSelect>
						<view class="" style="margin-left: 8rpx;">
							<u-icon name="arrow-down" size="16"></u-icon>
						</view>
					</view>

				</view>
			</view>
		</u-sticky>
		<view class="line">

		</view>
		<view class="body">
			<view class="" style="display: flex;flex-direction: column;">
				<view class="item" v-for="(item,index) in dataList" :key="index"
					@tap.stop="Jump(`/pages/home/stadiumDetail?id=${item.id}`)" v-if="index == 0">
					<view class="top1">
						<image :src="$imageOss(item.image)" mode="widthFix" style="" class="image"></image>
						<view class="top">
							{{item.title}}
						</view>
						<view class="bot">
							<text class="bot1">地址：{{item.address}} </text>
						</view>
					</view>
				</view>
			</view>

			<view class="" style="display: flex;justify-content: space-between;flex-wrap: wrap;padding: 10rpx;">
				<view class="item2" v-for="(item,index) in dataList" :key="index"  v-if="index != 0"
					@tap.stop="Jump(`/pages/home/stadiumDetail?id=${item.id}`)">
					<view class="top1">
						<image :src="$imageOss(item.image)" mode="widthFix" style="" class="image"></image>
						<view class="under">
							<view class="top">
								{{item.title}}
							</view>
							<view class="bot">
								<text class="bot1">地址：{{item.address}} </text>
							</view>
						</view>
					</view>
				</view>
			</view>

			<u-loadmore :status="status" />
		</view>
	</view>
</template>
<script>
	import vvSelect from '@/components/vv-select/index.vue'
	import {
		venueCategory,
		venueList
	} from "@/request/homeApi.js";
	export default {
		components: {
			vvSelect
		},
		data() {
			return {
				typeList: [],
				placeholder1: '全部类型',
				placeholder2: '最新',
				orderList: [{
					id: '',
					name: '最新'
				}, {
					id: 'like',
					name: '最热'
				}],
				queryForm: {
					title: '',
					venue_category_id: '',
					type: '',
					page: 1,
					limit: 10,
					recommend: ''
				},
				dataList: [],
				status: "nomore", // 加载状态
			};
		},
		onReachBottom() {
			let that = this
			if (that.queryForm.page < that.last_page) {
				that.queryForm.page = that.queryForm.page + 1
				that.getList()
			}
		},
		onShow() {
			this.queryForm.page = 1
			console.log(this.queryForm.page,'page')
			this.dataList = []
			this.queryForm.title = uni.getStorageSync('title') ? uni.getStorageSync('title') : ''
			this.getList();
			this.getTypeList();
		},
		methods: {
			// 跳转
			Jump(url) {
				uni.navigateTo({
					url: url
				})
			},

			// 类型切换
			tabChange(e) {
				this.queryForm.venue_category_id = e
				this.dataList = []
				this.getList()
			},

			// 排序
			orderChange(e) {
				this.queryForm.type = e
				this.dataList = []
				this.getList()
			},

			// 获取订场馆类型
			getTypeList() {
				let that = this
				venueCategory().then((res) => {
					res.data.unshift({
						name: "全部类型",
						id: ""
					});
					that.typeList = res.data;
				});
			},

			// 获取订场馆列表
			getList() {
				this.status = "loading";
				let that = this
				venueList(that.queryForm).then(res => {
					if (res.code == 200) {
						that.dataList = that.dataList.concat(res.data.list)
						that.last_page = Math.ceil(res.data.count / res.data.list.length)
						res.data.count == 0 ? that.status = 'nomore' : that.status = ''
					}else{
						uni.showToast({
							title: res.msg,
							duration: 1500,
							icon: 'none',
						})
					}
				})
			},
			// 搜索
			handleSearch() {
				this.queryForm.page = 1;
				this.dataList = []
				this.getList();
			},
			// 清空
			clearSearch() {
				this.queryForm.title = ''
				this.queryForm.page = 1;
				this.dataList = []
				this.getList();
			},
		},
	};
</script>
<style lang="scss" scoped>
	.page {
		.chooseCup {
			margin-right: 8rpx !important;

			image {
				width: 20rpx !important;
				height: 12rpx !important;
				margin: 14rpx;
			}
		}

		.line {
			height: 2rpx;
			width: 100%;
			background: #D9D9D9;
			z-index: 1000;
		}

		.body {
			background: #fff;
			padding: 4rpx 0;

			.item {
				padding: 10rpx 0 20rpx;

				.top1 {
					display: flex;
					flex-direction: column;
					margin: 20rpx 20rpx 0;

					.image {
						width: 100%;
						height: 440rpx !important;
						border-radius: 10rpx;
					}

					.top {
						color: #313131;
						font-family: PingFang SC;
						font-size: 30rpx;
						font-style: normal;
						font-weight: 400;
						line-height: normal;
						margin-top: 20rpx;
					}

					.bot {
						display: flex;
						flex-direction: row;
						justify-content: space-between;
						margin-top: 14rpx;

						.bot1 {
							color: #909090;
							font-family: PingFang SC;
							font-size: 26rpx;
							font-style: normal;
							font-weight: 400;
							line-height: normal;
						}
					}
				}
			}

			.item2 {
				width: 50%;

				.top1 {
					display: flex;
					flex-direction: column;
					margin: 10rpx;

					.under {
						padding-bottom: 16rpx;
					}

					.image {
						width: 100%;
						height: 180rpx !important;
						border-radius: 10rpx;
					}

					.top {
						color: #313131;
						font-family: PingFang SC;
						font-size: 30rpx;
						font-style: normal;
						font-weight: 400;
						line-height: normal;
						margin-top: 20rpx;
					}

					.bot {
						display: flex;
						flex-direction: row;
						justify-content: space-between;
						margin-top: 14rpx;

						.bot1 {
							color: #909090;
							font-family: PingFang SC;
							font-size: 26rpx;
							font-style: normal;
							font-weight: 400;
							line-height: normal;
						}
					}
				}
			}

			.f-bottom {
				font-weight: 600;
				font-size: 28rpx;
				color: $active-color;
				margin-left: 20rpx;

				text:nth-child(2) {
					font-size: 24rpx;
				}

				text:last-child {
					font-size: 40rpx;
				}
			}
		}

		.tabBox {
			display: flex;
			justify-content: space-evenly;
			width: 100%;
			padding: 10rpx 0 0;
			box-sizing: border-box;
			text-align: center;
			font-size: 30rpx;

			/deep/.u-scroll-list {
				width: 100%;
				padding-bottom: 0;
			}

			.leftIcon {
				width: 120rpx;
				height: 3rpx;
				margin: 14rpx auto;
			}

			.navItem {
				width: 160rpx;
				text-align: center !important;
				overflow: hidden;
			}
		}
	}
</style>